package com.dysm.spring.security.resource.config.filter;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 过滤器注册方式：2、通过 组件注解 注册
 */
//@Component
public class RequestBodyHandleFilter implements Filter {

    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @Override
    public void init(FilterConfig filterConfig) {
        log.debug("call RequestBodyHandleFilter.init...");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.debug("call RequestBodyHandleFilter.doFilter...");
        ReadBodyHttpRequestWrapper readBodyHttpRequestWrapper = new ReadBodyHttpRequestWrapper((HttpServletRequest) request);
        chain.doFilter(readBodyHttpRequestWrapper, response);
    }

    @Override
    public void destroy() {
        log.debug("call RequestBodyHandleFilter.destroy...");
    }
}
